/*    */ package com.zimbra.cs.httpclient;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Server;
/*    */ import java.net.URI;
/*    */ import java.net.URISyntaxException;
/*    */ import org.apache.commons.httpclient.HostConfiguration;
/*    */ import org.apache.commons.httpclient.HttpClient;
/*    */ import org.apache.commons.httpclient.HttpState;
/*    */ import org.apache.commons.httpclient.UsernamePasswordCredentials;
/*    */ import org.apache.commons.httpclient.auth.AuthScope;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class HttpProxyUtil
/*    */ {
/* 32 */   private static String sProxyUrl = null;
/* 33 */   private static URI sProxyUri = null;
/* 34 */   private static AuthScope sProxyAuthScope = null;
/* 35 */   private static UsernamePasswordCredentials sProxyCreds = null;
/*    */   
/*    */   public static synchronized void configureProxy(HttpClient client) {
/*    */     try {
/* 39 */       String url = Provisioning.getInstance().getLocalServer().getAttr("zimbraHttpProxyURL", null);
/* 40 */       if (url == null) { return;
/*    */       }
/*    */       
/* 43 */       if ((sProxyUrl == null) || (!sProxyUrl.equals(url))) {
/* 44 */         sProxyUrl = url;
/* 45 */         sProxyUri = new URI(url);
/* 46 */         sProxyAuthScope = null;
/* 47 */         sProxyCreds = null;
/* 48 */         String userInfo = sProxyUri.getUserInfo();
/* 49 */         if (userInfo != null) {
/* 50 */           int i = userInfo.indexOf(':');
/* 51 */           if (i != -1) {
/* 52 */             sProxyAuthScope = new AuthScope(sProxyUri.getHost(), sProxyUri.getPort(), null);
/* 53 */             sProxyCreds = new UsernamePasswordCredentials(userInfo.substring(0, i), userInfo.substring(i + 1));
/*    */           }
/*    */         }
/*    */       }
/* 57 */       if (ZimbraLog.misc.isDebugEnabled()) {
/* 58 */         ZimbraLog.misc.debug("setting proxy: " + url);
/*    */       }
/* 60 */       client.getHostConfiguration().setProxy(sProxyUri.getHost(), sProxyUri.getPort());
/* 61 */       if ((sProxyAuthScope != null) && (sProxyCreds != null))
/* 62 */         client.getState().setProxyCredentials(sProxyAuthScope, sProxyCreds);
/*    */     } catch (ServiceException e) {
/* 64 */       ZimbraLog.misc.warn("Unable to configureProxy: " + e.getMessage(), e);
/*    */     } catch (URISyntaxException e) {
/* 66 */       ZimbraLog.misc.warn("Unable to configureProxy: " + e.getMessage(), e);
/*    */     }
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/httpclient/HttpProxyUtil.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */